package com.atguigu.yygh.cmn.controller.user;

import com.atguigu.yygh.cmn.service.DictService;
import com.atguigu.yygh.common.result.R;
import com.atguigu.yygh.model.cmn.Dict;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping("/user/dict")
public class UserDictController {

    @Autowired
    private DictService dictService;

    //查詢全部的省份信息
    @GetMapping("/{dictCode}")
    public R getAllProvince(@PathVariable String dictCode){
        List<Dict> dictList = dictService.getAllProvince(dictCode);
        return R.ok().data("items",dictList);
    }

    @GetMapping("/children/{pid}")
    public R getChildrenByPid(@PathVariable Long pid){
        long start = System.currentTimeMillis();
        List<Dict> dicts= dictService.getChildrenByPid(pid);
        long end = System.currentTimeMillis();
        System.out.println("总共花费:"+(end-start)+"ms");
        return R.ok().data("items",dicts);
    }
}
